package cn.geckos.flexforum
{

import flash.events.EventDispatcher;

import cn.geckos.flexforum.events.GlobalActionEvent;

/**
 * 会员注册事件
 */ 
[Event(name="memberRegister", type="cn.geckos.flexforum.events.GlobalActionEvent")]
	
/**
 * 全局行为
 * 在多处可能会触发的同一行为视为全局行为，
 * 在可能触发的地方注册该类的监听，
 * 触发的时候调用该类的方法，由该类统一发出事件
 * 
 * [注] 该类为单列，使用 <code>GlobalAction.getInstance();</code>获取实例引用
 * 
 * @author harry 
 */
public class GlobalAction extends EventDispatcher
{
	private static var _instance:GlobalAction;
	
	/**
	 * 获取实例引用
	 */ 
	public static function getInstance():GlobalAction
	{
		if(GlobalAction._instance == null)
			GlobalAction._instance = new GlobalAction(new SingletonEnforcer());
		return GlobalAction._instance;
	}
	
	/**
	 * 单列
	 */ 
	public function GlobalAction(enforcer:SingletonEnforcer)
	{
		if(enforcer == null)
			throw new Error("Arguments Error: Can not to be null." + 
							"You should use 'getInstance()' for instance reference.");
	}
	
	/**
	 * 会员注册
	 */ 
	public function performMemberRegister():void
	{
		this.dispatchEvent(new GlobalActionEvent(GlobalActionEvent.MEMBER_REGISTER));
	}
	
}
}

class SingletonEnforcer {}